﻿using B.S.BasicData.Api.Write.Application.Command.User;
using B.S.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Write.Controllers
{
    /// <summary>
    /// 用户控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class UserController : ControllerBase
    {
        private readonly IMediator mediator;

        public UserController(IMediator mediator) 
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加用户信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> AddUser(AddUserCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除用户信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> DelUser(DelUserCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> UpdateUser(UpdateUserCommand request)
        {
            return mediator.Send(request);
        }
    }
}
